package com.jinly.ryder.schedule;


import com.jinly.ryder.build.config.BuildProperties;
import com.jinly.ryder.build.service.BuildArtifactService;
import com.jinly.ryder.build.service.BuildService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class BuildTask {

    private final BuildProperties buildProperties;
    private final BuildArtifactService buildArtifactService;
    private final BuildService buildService;

    /**
     * 清理构建产物
     */
    @Scheduled(fixedRate = 1000 * 60 * 60 * 6, initialDelay = 20 * 1000)
    public void clearArtifacts() {
        if (!buildProperties.isCleanArtifactEnable()) return;
        int maxNum = buildProperties.getArtifactMaxNum();
        buildArtifactService.clearArtifacts(maxNum);
    }

    @Scheduled(fixedRate = 1000 * 2, initialDelay = 20 * 1000)
    public void batchRefreshBuildStatus() {
        if (!buildProperties.isRefreshStatusEnable()) return;
        buildService.batchRefreshBuildStatus();
    }
}
